#ifndef _CORE_RESOURCEMANAGER__H_
#define _CORE_RESOURCEMANAGER__H_

#include <string>
#include <map>
#include <vector>
#include "resource.h"

namespace core
{

    class ResourceManager
    {
        public:
            //! Returns a resource by the name of p_Name, if its not found a empty ptr is returned.
            ResourcePtr GetResource( const std::string& p_Name );

            //! Adds a resource to the manager.
            void        AddResource( const std::string& p_Name, ResourcePtr p_Resource );

            //! Returns if an item is in the resourcemanager or not.
            bool        GotResource( const std::string& p_Name )
            {
                return( (bool)GetResource( p_Name ) );
            }

            //! Remove all not used resources.
            //! Should not be called very often.
            void        GarbageCollection()
            {
                std::vector<std::string>    RemoveList;
                ResourceSet::iterator iter = m_Resources.begin();
                ResourceSet::iterator  end = m_Resources.end();
                while( iter != end )
                {
                    if( iter->second.expired() )
                        RemoveList.push_back( iter->first );

                    iter++;
                }

                for( std::vector<std::string>::iterator iter = RemoveList.begin();
                     iter != RemoveList.end();
                     iter++ )
                {
                    m_Resources.erase( (*iter) );
                }

            }

        protected:
            typedef std::map< std::string, ResourceWeakPtr >   ResourceSet;
            ResourceSet m_Resources;


            // singelton
        public:
            static ResourceManager*    GetInstance();

            // singelton
        private:
            ResourceManager() {}
            ResourceManager( const ResourceManager& ) {}
            static ResourceManager*    m_Instance;

		};

}

#endif